package demo2;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Myserver {
public static void main(String[] args) {
	try {
		
		ServerSocket server=new ServerSocket(8000);
		
		System.out.println("等待客户端。。。");
		
			Socket s = server.accept();
		
			send(s, "服务器欢迎你！");
			Scanner in = new Scanner(System.in);
			String str=in.nextLine();
			while(!str.equals("bye")){
				send(s, str);
				str=in.nextLine();
			}
			
		
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}
public static void send(Socket socket,String message) {
	try {
		ObjectOutputStream oos=new ObjectOutputStream(
				socket.getOutputStream());
		oos.writeObject(message);
		oos.flush();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
}
